<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>修改密码</title>
	</head>
	<link rel="stylesheet" href="../css/mui.min.css" />
	<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
	<style>
		.headbar {
			background-color: #3ac9af;
		}
		
		.mui-icon-left-nav {
			color: white;
		}
		
		.mui-title {
			color: white;
		}
		.mui-content{
			color:#787878;
			font-size: 14px;
		}
		.d1{
			margin:20px 0px 7px 15px;
		}
		.d2{
			margin:7px 0px 7px 15px;
		}
		input[type="password"]{
			margin-bottom: 0px;
			border-radius: 0px;
			border: 0px solid white;
			font-size:14px;
		}
		.button {
				background-color: #3ac9af;
				border-color: #3ac9af;
				margin-top: 30px;
			}
	</style>

	<body>
		<header class="mui-bar mui-bar-nav headbar">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改密码</h1>
		</header>
		<div class="mui-content">
            <div class="d1">当前密码</div>
			<input type="password" id="oldpassword" placeholder="输入6-10个字符,区分大小写">
			 <div class="d2">新密码</div>
			<input type="password" class="p2" style="border-bottom: 1px solid #dddddd;" id="newpassword1" placeholder="输入6-10个字符,区分大小写">
			<input type="password" id="newpassword2" placeholder="请再次输入新密码">
		</div>
		<div class="button submit">确定</div>
	</body>
	<script type="text/javascript" src="../js/mui.min.js"></script>
	<script src="../script/config.js"></script>
	<script src="../script/moocpublic.js"></script>
	<script src="../js/DMobileFrame_DownLoadUtil.js"></script>
    <script>
    	var localStorageManagers = require("script/localStorageManagers.js");
		var downloadUtils = require('scripts/Core/DownLoadUtil.js');
		var mobileFrame = require('scripts/Core/MobileFrame.js');
		//mui初始化
		mui.init({
			swipeBack: true
		});
		//plus初始化
		mui.plusReady(plusReady);
		//plusReady
		function plusReady() {
			//确定
			mui('body').on('tap', '.submit', updatepassword);
		};
		//修改密码
		function updatepassword(){
			if(!mobileFrame.IsNetWorkCanUse())return;
			var oldpassword=document.getElementById('oldpassword').value;
		    var newpassword1=document.getElementById('newpassword1').value;
			var newpassword2=document.getElementById('newpassword2').value;
			if(oldpassword==''){
				mui.toast('请输入当前密码');
				return;
			}
			if(newpassword1==''){
				mui.toast('请输入新密码');
				return;
			}
			if(newpassword2==''){
				mui.toast('请再次输入新密码');
				return;
			}
			if(newpassword1.length<6||newpassword1.length>10){
				mui.toast('新密码长度应该大于6小于10');
				return;
			}
			if(newpassword1!=newpassword2){
				mui.toast('两次输入的新密码不一致');
				return;
			}
			var userid=localStorageManagers.getUseridSession();
			var url=serverAjax+'mobile/user/updatePassword.do';
			var data={
				userid:userid,
				oldpassword:oldpassword,
				newpassword:newpassword1
			};
			mui.ajax(url,{
				data:data,
				type:'post',
				dataType:'json',
				timeout:10000,
				success:function(data){
					if(data.type==1){
					   mui.toast('修改密码成功');
					   mui.back();
					}else if(data.type==0){
						 mui.toast('当前密码不正确');
					}else if(data.type==-1){
						mui.toast('修改失败,请刷新后重试');
					}
					
				},
				error:function(e1,e2,e3){
					console.log(e1);
					ajaxErrorTip();
				}
			});
		}
    </script>
</html>